package threadpool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 描述：支持定时及周期性任务执行的线程池
 */
public class ScheduledThreadPoolTest {

    public static void main(String[] args) {
        ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(10);
        //该任务会在延迟 5 秒后开始执行
        //threadPool.schedule(new Task(), 5, TimeUnit.SECONDS);
        //该任务会在延迟 1 秒后开始执行，并且每隔 3 秒执行一次
        threadPool.scheduleAtFixedRate(new Task(), 1, 3, TimeUnit.SECONDS);
    }
}
